<template>
  <Nav :showBlack="true" :title="de_data.name"></Nav>
  <div class="page">
    <div class="main-info">
      <div class="imgBox" :style="{ backgroundImage: `url(${de_data.cover_image})`}"></div>
      <div class="nameBox">
        <div class="name">{{de_data.name}}</div>
        <div class="control">
          <div class="viewBox">
            <img src="../assets/look.png" alt="">
            <span>{{de_data.browse_count}}</span>
          </div>
          <div class="likeBox" v-show="de_data.has_like == 0" @click="collection(de_data)">
            <img src="../assets/like.png" alt="">
            <span>{{de_data.like_count}}</span>
          </div>
          <div class="likeBox" v-show="de_data.has_like == 1" @click="uncollection(de_data)">
            <img src="../assets/collect-a.png" alt="">
            <span>{{de_data.like_count}}</span>
          </div>
        </div>
      </div>
      <div class="tags">
        <div class="tag" v-for="(item,index) in tags">{{item}}</div>
      </div>
      <div class="info" v-if="de_data.descript" :class="{close:open}">
        <div :class="{close:!open}">{{removeTags(de_data.descript)}}</div>
        <div class="tiggeOpen" @click="tiggeOpen">
          <span v-show="!open">展开详情</span>
          <span v-show="open">收起详情</span>
        </div>
      </div>
      <div class="controlBox">
         <div class="cont border" @click="showShare()">
           <img src="../assets/share.png" alt="" >
           分享藏品
         </div>
         <div class="cont" v-show="de_data.has_like == 0" @click="collection(de_data)">
           <img src="../assets/like.png" alt="">
           点赞藏品
         </div>
        <div class="cont" v-show="de_data.has_like == 1" @click="uncollection(de_data)">
          <img src="../assets/collect-a.png" alt="">
          点赞藏品
        </div>
      </div>
    </div>
    <div class="itemSwiper">
       <div class="s-title">
         <div>本系列藏品</div>
         <div>{{coll_data.length}}件藏品</div>
       </div>
      <div class="swiperBox">
        <div class="leftBr">
          <img src="../assets/left-arrow.png" alt="" @click="pre">
        </div>
        <div class="inner">
          <van-swipe class="my-swipe" ref="swiperTop"  @change="onChange" indicator-color="white">
            <van-swipe-item class="swipe-item" v-for="(item,index) in coll_data" :key="item.id" :style="{ backgroundImage: `url(${item.full_img})`}">
            </van-swipe-item>
          </van-swipe>
        </div>
        <div class="rightBr">
          <img src="../assets/right-arrow.png" alt="" @click="next">
        </div>
      </div>
      <div class="items-info">
         <div class="info-title">
           <span class="name">{{de_data.name}}</span>
<!--           <span>-->
<!--             <img src="../assets/like.png" alt="">-->
<!--             {{de_data.has_like}}-->
<!--           </span>-->
         </div>
<!--        <div class="f-title">-->
<!--          宣纸载茶经，手礼传古韵。-->
<!--        </div>-->
        <div class="btns">
          <div class="btn" @click="goParic">
            详情鉴赏
          </div>
        </div>
      </div>
    </div>
    <van-tabs v-model:active="active"  @click-tab="onClickTab" line-height="0" ref="tabsRef" background="#0f1830">
      <van-tab v-for="(item,index) in coll_data" :key="item.id">
        <template #title>
          <div class="tab-item">
            <div class="imgBox" :class="{active:active == index}" :style="{ backgroundImage: `url(${item.full_img})`}">

            </div>
          </div>
        </template>
      </van-tab>
    </van-tabs>
    <div class="courseBlock">
        <div class="head" v-show="res_data.length > 0">
          数字课程
        </div>
        <div class="items">
          <div class="item" v-for="(item,index) in res_data"  :key="item.id" @click="goVideoDetail(item)">
            <div class="imgbox"  :style="{ backgroundImage: `url(${item.cover_image})`}"></div>
            <div class="infoBox">
              <div class="info-title">{{item.name}}</div>
              <div class="info-minTitle">{{removeTags(item.descript)}}</div>
            </div>
          </div>
        </div>
    </div>
</div>
<sharehtml></sharehtml>
</template>
<script setup>
import Nav from '@/components/nav.vue'
import sharehtml from '@/components/sharehtml.vue'
import { removeTags } from '@/utils/utils'
import {useRoute, useRouter} from 'vue-router'
import { onMounted, reactive, ref, onActivated, nextTick } from 'vue';
import { api } from "@/utils/api.js";
import { showToast } from "vant";
import {mainStore, shareStore} from '@/store/index.js';
const mainStoreObj = mainStore();
const shareOjb = shareStore();
const router = useRouter();
const route = useRoute();
const swiperTop = ref(null)
const active = ref(0);
const swiperIndex = ref(0);
const goId = ref('');
const open = ref(false);
let de_data = ref({});
let tags = reactive([]);
let coll_data = reactive([]);
let res_data = reactive([]);

async function render() {
  const res = await api('/api/collectionclassify/classify_detail','post',{id:route.query.id})
  console.log(res);
  de_data.value = res.collect_classify;
  coll_data.push(...res.collection_detail_list);
  console.log(coll_data);
  goId.value = coll_data[0].id;
  const array =res.collect_classify.tag.split('，');
  tags.push(...array);
  res_data.push(...res.collection_resource_list);
  console.log(res_data)
}

onMounted(() => {
  render();
})

const showShare = () => {
  shareOjb.show();
}

const onChange = (index) => {
  // console.log(index)
  swiperIndex.value = index;
  active.value = index;
}

const goVideoDetail = (item) => {
  // console.log(src)

  mainStoreObj.changeSrc(item);
  router.push({path:'videoDetail',query:{id:item.id}})
}

const pre = (index) => {
  swiperTop.value.prev();
  // swiperItem.value.prev();
}

const next = (index) => {
  swiperTop.value.next()
  // swiperItem.value.next();
}

const tiggeOpen = () => {
  open.value = !open.value;
}

async function collection (item) {
  const res = await api('/api/index/collection_classify_like','post',{id:route.query.id})
  //console.log(res);
  if(Array.isArray(res)) {
    de_data.value.has_like = 1;
    de_data.value.like_count ++;
    showToast('点赞成功');
  }
}

async function uncollection (item) {
  const res = await api('/api/index/collection_classify_cancle_like','post',{id:route.query.id})
  //console.log(res);
  if(Array.isArray(res)) {
    de_data.value.has_like = 0
    de_data.value.like_count --;
    showToast('取消点赞成功');
  }
}

const goThis = (index) => {
  // console.log(swiperTop)
  swiperTop.value.swipeTo(index);
  // swiperItem.value.swipeTo(index);
}

const onClickTab = (item) => {
  console.log(item)
  const index = item.name;
  goId.value =  coll_data[index].id;
  swiperTop.value.swipeTo(index);
  de_data.value.name = coll_data[item.name].name;
};

const goParic = () => {
  router.push({path:'particulars',query:{id:goId.value}})
}
</script>
<style scoped lang="scss">
@import '@/assets/style/mixin';
:deep(.van-tab--grow) {
  padding: 0 5px;
}
:deep(.van-tabs--line .van-tabs__wrap) {
  height: auto;
}
.page {
  background: #0f1830;
  padding-top: 170px;
  padding-bottom: 200px;
  color:#fff;
}

.tab-item {
  width: 240px;
  height: 240px;
  //border:1px solid #ddd;
  padding: 10px;
  .imgBox {
    width: 100%;
    height: 100%;
    //background-color:pink;
    &.active {
      transform: scale(1.1);
    }
  }
}

.main-info {
  width: 100%;
  padding:0 58px;
  background: #0a0f18;
  .imgBox {
    width: 100%;
    height: 722px;
    border-radius: 24px;
    margin-bottom: 50px;
  }
}
.nameBox {
  display: flex;
  justify-content: space-between;
  height: 90px;
  .name {
    font-size: 46px;
  }
  .control {
    display: flex;
    justify-content: space-between;
    height: 90px;
    > div {
      margin-left: 40px;
      font-size: 40px;
      img {
        height: 40px;
        width: auto;
        margin-right:10px;
        vertical-align: text-bottom;
      }
    }
  }
}
.tags {
  overflow: hidden;
  margin-bottom: 20px;
  .tag {
    float: left;
    font-size:32px;
    background: #f4eacf;
    color:#040810;
    font-weight: bold;
    padding: 10px 16px;
   border-radius: 10px;
    margin-right: 20px;
  }
}
.info {
  font-size: 36px;
  line-height: 2;
  margin-bottom: 20px;
  .close {
    height: 290px;
    overflow: hidden;
  }
  .tiggeOpen {
    text-align: center;
    font-size: 42px;
    padding-bottom: 40px;
  }
}


.controlBox {
  border:3PX solid #f4eacf;
  border-radius: 20px;
  padding: 42px 0;
  display: flex;
  margin-bottom: 40px;
  .cont {
    flex: 1;
    height: 30px;
    font-size: 36px;
    color:#f4eacf;
    display: flex;
    justify-content: center;
    align-items: center;
    img {
      margin-right: 16px;
      height: 50px;
    }
    &.border {
      border-right: 3PX solid #f4eacf;
    }
  }
}
.itemSwiper {
  padding: 0  50px;
  .s-title {
    display: flex;
    justify-content: space-between;
    font-size: 38px;
    margin-bottom: 80px;
  }
  .swiperBox {
    display: flex;
    margin-right: -30px;
    margin-left: -30px;
    margin-bottom: 46px;
    .leftBr {
      flex:1;
      height: 873px;
      @include center();
      img {
        width: 76px;
        height: 76px;
      }
    }
    .rightBr {
      flex:1;
      height: 873px;
      @include center();
      img {
        width: 76px;
        height: 76px;
      }
    }
    .inner {
      width: 680px;
      height: 873px;
      flex:none;
      //background: pink;
    }
  }
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  //background-color: #39a9ed;
  height: 873px;
}

.swipe-item {
  background-size: cover;
  background-position: center;
}

.items-info {

  .info-title {
    font-size: 40px;
    margin-bottom: 30px;
    img {
      width: 42px;
    }
    .name {
      font-size: 46px;
      margin-right: 42px;
    }
    @include center();
  }
  .f-title {
    font-size: 40px;
    margin-bottom: 60px;
    @include center();
  }
  .btns {
    margin-bottom: 60px;
    @include center();

    .btn {
      font-size: 40px;
      padding: 25px;
      border:3px solid #fff;
      width: 320px;
      border-radius: 15px;
      @include center()
    }
  }
}
.van-swipe-item {
  display: flex;
  @include center();
}
.imgBoxInner {
   width: 80%;
  height: 80%;
  //background: pink;
  border-radius: 14px;
  &.big {
    width: 94%;
    height: 94%;
  }
}
.courseBlock {
  padding: 42px 58px;
  .head {
      font-size: 46px;
      margin-bottom: 60px;
  }
}

.item {
  border:1px solid #484a4a;
  border-radius: 34px;
  padding: 40px;
  margin-bottom: 40px;
  display: flex;
  .imgbox {
    width: 146px;
    height: 146px;
    border-radius:15px;
    //background: pink;
    background-size: cover;
    background-position: center;
    flex: none;
  }
  .infoBox {
    margin-left: 40px;

     .info-title {
       font-size: 46px;
       margin-bottom: 15px;
     }
    .info-minTitle {
      font-size: 32px;
      line-height: 1.3;
      @include ellipsis2(2)
    }
  }
}
</style>
